from openpyxl import load_workbook

workbook = load_workbook(filename="/home/thseus/workspaces/python/test.xlsx")
print(workbook.sheetnames)

sheet = workbook["工作表1"]

print(sheet)

print(sheet.dimensions)

cell1 = sheet["A1"]
cell2 = sheet["F2"]
print(cell1.value, cell2.value)
"""
workbook.active 打开激活的表格;
sheet["A1"] 获取 A1 格子的数据;
cell.value 获取格子中的值;
"""
cell1 = sheet.cell(row = 1,column = 1)
cell2 = sheet.cell(row = 11,column = 3)
print(cell1.value, cell2.value)


cell1 = sheet["A1"]
cell2 = sheet["C11"]
print(cell1.value, cell1.row, cell1.column, cell1.coordinate)
print(cell2.value, cell2.row, cell2.column, cell2.coordinate)
"""
.row 获取某个格子的行数;
.columns 获取某个格子的列数;
.corordinate 获取某个格子的坐标;
"""

# 获取 A1:C2 区域的值
cell = sheet["A1:C2"]
print(cell)
for i in cell:
    for j in i:
        print(j.value)

# 按行获取值
for i in sheet.iter_rows(min_row=2, max_row=5, min_col=1,
max_col=2):
    for j in i:
        print(j.value)
# 按列获取值
for i in sheet.iter_cols(min_row=2, max_row=5, min_col=1,
max_col=2):
    for j in i:
        print(j.value)

for i in sheet.rows:
    print(i)